﻿using MMS.UI.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.WebPages;
using System.Web.Mvc;

namespace MMS.UI.Areas.Admin.Controllers
{
    using MMS.Model.FormatModel;
    public class MembershipAnalysisController : BaseController
    {


        #region 1.0 加载 会员消费分析 图表
        [HttpGet]
        public ActionResult Consumption()
        {
            return View();
        }
        /// <summary>
        ///  会员总消费分析表格图
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Consumption(FormCollection form)
        {
            var data = OpeCur.GetAsync<List<class_Consumption>>("http://localhost:16824/api/MembershipAnalysis/GetConsumption");
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }
        /// <summary>
        /// 对单个会员的数据进行分析
        /// </summary>
        /// <param name="Id">会员Id</param>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult GetPersonConsumption(string Id)
        {
            int id = Convert.ToInt32(Id);
            var data = OpeCur.GetAsync<List<class_Consumption>>("http://localhost:16824/api/MembershipAnalysis/GetPersonConsumption/" + id);
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }
        /// <summary>
        /// 会员年度分析
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult GetAnnualConsumption()
        {
            var data = OpeCur.GetAsync<List<class_Consumption>>("http://localhost:16824/api/MembershipAnalysis/GetAnnualConsumption").ToList();
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }
        /// <summary>
        /// 会员月度分析
        /// </summary>
        /// <returns></returns>
        // [HttpPost]
        public ActionResult GetMonthlyConsumption()
        {
            var data = OpeCur.GetAsync<List<class_Consumption>>("http://localhost:16824/api/MembershipAnalysis/GetMonthlyConsumption").ToList();
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }
        #endregion

        #region 2.0 加载 会员地域分析 图表
        [HttpGet]
        public ActionResult Region()
        {
            return View();
        }

        public ActionResult Region(FormCollection form)
        {
            var maddress = OpeCur.GetAsync<List<class_Region>>("http://localhost:16824/api/MembershipAnalysis/GetMAddressAndGroupSumGroupByMAddress");
            var dataJson = OpeCur.ToJson(maddress);

            return Content(dataJson);
        }
        #endregion

        #region 3.0 加载 忠诚度分析图表
        public ActionResult Loyalty()
        {
            var list = OpeCur.GetAsync<List<class_Loyalty>>("http://localhost:16824/api/MembershipAnalysis/GetLoyalty");
            ViewBag.AllLoyalty = OpeCur.ToJson(list);
            return View();
        }
        [HttpPost]
        public ActionResult Loyalty(FormCollection form)
        {
            int pageIndex = Request.Form["page"].AsInt();
            int pageSize = Request.Form["rows"].AsInt();
            var data = OpeCur.GetAsync<PageData<class_Loyalty>>("http://localhost:16824/api/MembershipAnalysis/GetLoyalty1/" + pageIndex + "/" + pageSize);
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }
       
        public ActionResult MemberLoyalty(int id)
        {
            var list = OpeCur.GetAsync<List<class_Loyalty>>("http://localhost:16824/api/MembershipAnalysis/GetMemberLoyalty/"+id );
            ViewBag.data = OpeCur.ToJson(list);
           
            return View();
        }
       
        #endregion

        #region 4.0 加载 礼品兑换分析 图表
        [HttpGet]
        public ActionResult ExchangeGift()
        {
            return View();
        }
        [HttpPost]
        public ActionResult ExchangeGift(FormCollection from)
        {
            var data = OpeCur.GetAsync<List<class_ExchangeGift>>("http://localhost:16824/api/MembershipAnalysis/GetExchangeGift");
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }
        #endregion

        #region 5.0 加载 会员等级分析 图表
        [HttpGet]
        public ActionResult Level()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Level(FormCollection from)
        {
            var data = OpeCur.GetAsync<List<class_Level>>("http://localhost:16824/api/MembershipAnalysis/GetLevel");
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }

        #endregion

        #region 6.0 加载 购买商品推荐 图表
        public ActionResult Goods()
        {
            return View();
        }
        #endregion

        #region 7.0 加载 会员流失预警 图表
        [HttpGet]
        public ActionResult Loss()
        {
            return View();
        }

        [HttpPost]
        /// <summary>
        /// 获取三个月以上半年以内未消费者数据 
        /// </summary>
        /// <returns></returns>
        public ActionResult Loss(FormCollection from)
        {
            var data = OpeCur.GetAsync<List<class_Loss>>("http://localhost:16824/api/MembershipAnalysis/GetLoss");
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }

        /// <summary>
        /// 获取半年以上一年以内未消费者数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Loss1(FormCollection from)
        {
            var data = OpeCur.GetAsync<List<class_Loss>>("http://localhost:16824/api/MembershipAnalysis/GetLoss1");
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }

        /// <summary>
        /// 获取一年以上未消费者数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Loss2(FormCollection from)
        {
            var data = OpeCur.GetAsync<List<class_Loss>>("http://localhost:16824/api/MembershipAnalysis/GetLoss2");
            var dataJson = OpeCur.ToJson(data);
            return Content(dataJson);
        }
        #endregion


        #region 8.0 加载 会员群体分析 图表
        public ActionResult Colony()
        {
            var list = OpeCur.GetAsync<List<class_Colony>>("http://localhost:16824/api/MembershipAnalysis/GetColony/2000-01-01/2030-01-01");
            ViewBag.Colony = OpeCur.ToJson(list);
            return View();
        }
        [HttpPost]
        public ActionResult Colony(FormCollection form)
        {
            string startdate = Request.Form["startdate"];
            string enddate = Request.Form["enddate"];
            startdate = DateTime.ParseExact(startdate, "yyyy-MM-dd HH:mm:ss", null).ToString("yyyyMMddHHmmss");
            enddate = DateTime.ParseExact(enddate, "yyyy-MM-dd HH:mm:ss", null).ToString("yyyyMMddHHmmss");

            var Data = OpeCur.GetAsync<List<class_Colony>>("http://localhost:16824/api/MembershipAnalysis/GetColony/" + startdate + "/" + enddate);

            var strJson = OpeCur.ToJson(Data);
            return Content(strJson);
        }
        #endregion

        #region 9.0 加载 会员购物时段分析 图表
        public ActionResult Time()
        {
            var list = OpeCur.GetAsync<List<class_Time>>("http://localhost:16824/api/MembershipAnalysis/GetTime/2000-01-01/2030-01-01/按消费额度/0/10000");
            ViewBag.Data = OpeCur.ToJson(list);
            //3.将 实体对象 转成 视图模型对象 传给 视图
            return View();
        }
        [HttpPost]
        public ActionResult Time(FormCollection form)
        {
            string startdate = Request.Form["startdate"];
            string enddate = Request.Form["enddate"];
            string category = Request.Form["category"];
            string less = Request.Form["less"];
            string greater = Request.Form["greater"];

            startdate = DateTime.ParseExact(startdate, "yyyy-MM-dd HH:mm:ss", null).ToString("yyyyMMddHHmmss");
            enddate = DateTime.ParseExact(enddate, "yyyy-MM-dd HH:mm:ss", null).ToString("yyyyMMddHHmmss");

            var Data = OpeCur.GetAsync<List<class_Time>>("http://localhost:16824/api/MembershipAnalysis/GetTime/" + startdate + "/" + enddate + "/" + category + "/" + less + "/" + greater);

            var strJson = OpeCur.ToJson(Data);
            return Content(strJson);

        }
        #endregion

        #region 10.0 加载 会员购物金额分析 图表
        public ActionResult ShoppingAmount()
        {
            return View();
        }
        #endregion

        #region 11.0 加载 会员购物品类分析 图表
        public ActionResult Category()
        {
            var list = OpeCur.GetAsync<List<class_Member_category>>("http://localhost:16824/api/MembershipAnalysis/GetCategory/2000-01-01/2030-01-01/按消费额度/0/10000");
            ViewBag.Data = OpeCur.ToJson(list);
            //3.将 实体对象 转成 视图模型对象 传给 视图
            return View();
        }
        [HttpPost]
        public ActionResult Category(FormCollection form)
        {
            string startdate = Request.Form["startdate"];
            string enddate = Request.Form["enddate"];
            string category = Request.Form["category"];
            string less = Request.Form["less"];
            string greater = Request.Form["greater"];

            startdate = DateTime.ParseExact(startdate, "yyyy-MM-dd HH:mm:ss", null).ToString("yyyyMMddHHmmss");
            enddate = DateTime.ParseExact(enddate, "yyyy-MM-dd HH:mm:ss", null).ToString("yyyyMMddHHmmss");

            var Data = OpeCur.GetAsync<List<class_Member_category>>("http://localhost:16824/api/MembershipAnalysis/GetCategory/" + startdate + "/" + enddate + "/" + category + "/" + less + "/" + greater);

            var strJson = OpeCur.ToJson(Data);
            return Content(strJson);

        }
        #endregion


        #region 12.0 加载 促销活动响应分析 图表
        public ActionResult Promotion()
        {
            return View();
        }
        #endregion


      

       
    }
}
